<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<HTML>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>留言列表</title>
<!-- 引入样式 -->
<link href="${pageContext.request.contextPath}/css/Style1.css"
	rel="stylesheet" type="text/css" />
<link
	href="${ pageContext.request.contextPath }/static/bootstrap-3.3.7-dist/css/bootstrap.min.css"
	rel="stylesheet">
<script type="text/javascript"
	src="${ pageContext.request.contextPath }/static/js/jquery-2.1.1.min.js"></script>

<script type="text/javascript">
function Reply(messageid) {
	window.location.href = "${pageContext.request.contextPath}/admin/adminMessage_edit.action?messageid="+messageid;
}

	function dele(messageid) {
		var r = confirm("确定删除吗？");
		if (r == true) {
			window.location.href = "${pageContext.request.contextPath }/admin/adminMessage_delete.action?messageid="
					+ messageid;
			alert("删除成功！");
		} else {
			alert("取消删除");
		}
	}
	
	//批量删除
	$(function(){
	    $("#deleteSkills").click(function(){
	        //判断是否至少选择一项
	        var checkedNum = $("input[name='ids']:checked").length;
	        if(checkedNum==0){
	            alert("请至少选择一项");
	            return;
	        }
	        if(confirm("确定要删除所选留言？")){
	            //这个数组存储要删除的数据的id
	            var checkedList = new Array();
	            //每一个被选中的name为ids的input标签
	            $("input[name='ids']:checked").each(function(){
	                checkedList.push($(this).val());//将id存入数组
	            });
	            $.ajax({
	                type:"post",
	                dataType:"json",
	                url:"${pageContext.request.contextPath}/deleteMessage.action",//不同页面只用更改action即可
	                async:true,
	                //数组的toString里的id是用","分隔开的，例如数组{"1","2","3"},同String后为"1,2,3"
	                data:{"deleteList":checkedList.toString()},
	                success:function(data){
	                    if(data==1){
	                        for(var i=0;i<checkedList.length;i++){
	                            $("#tr_"+checkedList[i]).remove();//ajax动态移除
	                        }
	                        alert("删除成功");
	                    }else{
	                        alert("删除失败");
	                    }
	                    window.location.reload();
	                },
	                error:function(){
	                    alert("error");
	                }
	             })
	         }
	     })
	              			
	})
	       // window.location.reload();
</script>
</head>
<body>
	<div align="right" style="padding-right: 60px;">
		<input id="deleteSkills" type="button" value="-批量删除-"
			style="margin-top: 10px;" onclick="chooseShip()"
			class="btn btn-danger" />
	</div>

	<div style="width: 96%; margin-left: 23px;">
		<form style="margin-top: 5px;">
			<table width="100%" align="center"
				class="table table-hover table-bordered ">
				<thead>
					<tr bgcolor="#93b6bd" align="center">
						<th scope="col" width="10%" style="text-align: center;">序号</th>
						<th scope="col" width="14%" style="text-align: center;">用户昵称</th>
						<th scope="col" width="20%" style="text-align: center;">留言</th>
						<th scope="col" width="20%" style="text-align: center;">留言日期</th>
						<th scope="col" width="20%" style="text-align: center;">回复</th>
						<th scope="col" style="text-align: center;">操作</th>
					</tr>
				</thead>
				<c:forEach items="${pageBean.list}" var="message">
					<tr id="tr_${message.messageid }" style="height: 29px;">
						<td align="center" width="6%"><input name="ids"
							value="${message.messageid}" type="checkbox" /></td>
						<td align="center">${message.user.username}</td>
						<td align="center" width="17%">${message.message}</td>
						<td align="center" width="17%">${message.messagedate}</td>
						<td align="center" width="17%">${message.reply}</td>
						<td align="center">
							<button type="button"
								class="btn btn-danger btn-sm glyphicon glyphicon-trash"
								onclick="dele(${message.messageid})"></button>&nbsp;&nbsp;
							<button type="button"
								class="btn btn-primary btn-sm glyphicon glyphicon-edit"
								onclick="Reply(${message.messageid})"></button>
						</td>
					</tr>
				</c:forEach>
			</table>
		</form>
	</div>

	<div align="center">
		第${pageBean.page }/${pageBean.totlePage}页
		<c:if test="${pageBean.page!= 1}">
			<a
				href="${pageContext.request.contextPath }/admin/adminMessage_findAllByPage.action?page=1">首页</a>|
			     	<a
				href="${pageContext.request.contextPath }/admin/adminMessage_findAllByPage.action?page=${pageBean.page-1}">上一页</a>
		</c:if>
		<c:forEach begin="1" end="${pageBean.totlePage}" var="i">
			<c:choose>
				<c:when test="${pageBean.page!=i}">
					<a
						href="${ pageContext.request.contextPath }/admin/adminMessage_findAllByPage.action?page=${i}">${i}</a>
				</c:when>
				<c:otherwise>
					<span class="currentPage">${i}</span>
				</c:otherwise>
			</c:choose>
		</c:forEach>
		<c:if test="${pageBean.page!=pageBean.totlePage}">
			<a
				href="${pageContext.request.contextPath }/admin/adminMessage_findAllByPage.action?page=${pageBean.page+1}">下一页</a> |
							<a
				href="${pageContext.request.contextPath }/admin/adminMessage_findAllByPage.action?page=${pageBean.totlePage}">尾页</a>
		</c:if>
	</div>
</body>
</HTML>

